# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest

using("SideMenu_Open.air")
import SideMenu_Open
        
class SideMenu_ChangeGender(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))
        # 打开左侧菜单
        isOpenSideMenu = SideMenu_Open.runTest({})
        if not isOpenSideMenu:
            return False

        # 获取左侧菜单节点
        bottomPanel = poco("bottom_panel")
        if not bottomPanel.exists():
            return False

        # 获取切换性别按钮
        btnGender = bottomPanel.offspring("btn_sexBoy")
        if not btnGender.exists():
            btnGender = bottomPanel.offspring("btn_sexGirl")
            if not btnGender.exists():
                return False
        # 点击切换性别
        self.clickButton(btnGender)

        # 等待确认弹框弹出
        try:
            poco("LBTipsLayer").wait_for_appearance()
        except:
            assert_equal(False, True, "修改性别确认框弹出正常")
            return False
        # 获取确认框
        confirmDialog = poco("LBTipsLayer")
        # 获取确认按钮
        btnConfirm = confirmDialog.offspring("ok_btn_2")
        if not btnConfirm.exists():
            return False
        # 点击确认按钮
        self.clickButton(btnConfirm)
        # 获取提示信息，并进行比对是否“修改成功”
        toastView = poco("ToastView")        
        if toastView.exists():
            txtContent = toastView.offspring("text_content").get_text()
            assert_equal(txtContent, "修改成功", "修改性别成功")
        
        sleep(0.5)

        poco.click([0.7, 0.5])

        return True
        
_instance = SideMenu_ChangeGender()
runTest = _instance.runTest